<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/1/31 0031
 * Time: 上午 10:29
 */

namespace app\admin\model;

use think\Model;
use think\Db;
class User extends  Model
{
    protected  $pk='user_id';//主键
    protected $table = 'xcx_user';
    public function getAllData()
    {
        //$res=$this->order('user_id desc ')->select();
        $res= Db::table('xcx_user')
            ->alias('a')
            ->join('user_bill u','a.user_id=u.user_id')
            ->join('userimg g','a.headimg=g.img_id')
            ->select();

        return $res;
    }
    public function getUserAddr($id)
    {
        $data=db('user_address')->where('user_id',$id)->where('uaddres_states',1)->select();
        $user=db('user')->where('user_id',$id)->field('nickname')->find();
        $res=array(
            'data'=>$data,
            'user'=>$user
        );
        return $res;
    }
    public function getUserBill($id)
    {
        $data=db('user_account')->where('user_id',$id)->select();
        $user=Db::table('xcx_user')
            ->alias('a')
            ->join('user_bill l','a.user_id=l.user_id')
            ->where('a.user_id',$id)
            ->field('a.nickname,l.current_surplus')
            ->find();
        $res=array(
            'data'=>$data,
            'user'=>$user,
        );
        return $res;
    }
}